package com.ahu.rs.admin.controller;

import com.ahu.rs.admin.service.ImageService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class ImageController {
    @Resource
    private ImageService imageService;

    @PostMapping("/page")
    public Result page(@RequestBody ImagePageDTO imagePageDTO) {
        PageResult<ImageVO> page = imageService.page(imagePageDTO);
        return Result.success(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody ImageAddDTO imageAddDTO) {
        boolean added = imageService.add(imageAddDTO);
        return Result.info(added, null);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable("id") String id) {
        boolean deleted = imageService.delete(id);
        return Result.info(deleted, null);
    }

    @PostMapping("/batchDelete")
    public Result batchDelete(@RequestBody List<String> ids) {
        boolean deleted = imageService.batchDelete(ids);
        return Result.info(deleted, null);
    }

    @PutMapping("/update")
    public Result update(@RequestBody ImageUpdateDTO imageUpdateDTO) {
        boolean updated = imageService.update(imageUpdateDTO);
        return Result.info(updated, null);
    }

    @GetMapping("/{id}")
    public Result get(@PathVariable("id") String id) {
        ImageVO imageVO = imageService.get(id);
        return Result.success(imageVO);
    }

}
